<template>
  <div class="shop-container">
    <!-- 搜索区域 -->
    <div class="search-section">
      <div class="search-container">
        <div class="logo-section">
          <a href="/shop" class="logo-link">
            <div class="logo-text">
              <div class="logo-icon">
                <i class="el-icon-shopping-bag-1"></i>
              </div>
              <div class="logo-content">
                <span class="logo-main">悦购</span>
                <span class="logo-sub">MALL</span>
              </div>
            </div>
          </a>
        </div>
        
        <div class="search-box">
          <div class="search-input-wrapper">
            <el-input 
              v-model="search" 
              placeholder="请输入你搜索的商品关键词"
              class="search-input"
              @keydown.enter.native="loadData"
              clearable>
              <template #prefix>
                <i class="el-icon-search search-icon"></i>
              </template>
            </el-input>
            <el-button 
              type="primary" 
              class="search-btn"
              @click="loadData"
              icon="el-icon-search">
              搜索
            </el-button>
          </div>
        </div>
      </div>
    </div>

    <!-- 商品展示区域 -->
    <div class="products-section">
      <div class="products-container">
        <!-- 左侧排序筛选栏 -->
        <div class="filter-sidebar">
          <div class="filter-item" :class="{ active: selectedFilter === 'comprehensive' }" @click="selectFilter('comprehensive')">
            <i class="el-icon-s-grid"></i>
            <span class="filter-text">综合</span>
          </div>
          <div class="filter-item" :class="{ active: selectedFilter === 'category' }" @click="selectFilter('category')">
            <i class="el-icon-menu"></i>
            <span class="filter-text">分类</span>
          </div>
          <div class="filter-item" :class="{ active: selectedFilter === 'price' }" @click="selectFilter('price')">
            <i class="el-icon-goods"></i>
            <span class="filter-text">价格</span>
            <i v-if="priceSortOrder === 'asc'" class="el-icon-arrow-up sort-arrow"></i>
            <i v-if="priceSortOrder === 'desc'" class="el-icon-arrow-down sort-arrow"></i>
          </div>
        </div>
        
        <!-- 分类选择遮罩层 -->
        <div v-if="showCategoryPanel" class="category-overlay" @click="showCategoryPanel = false"></div>
        
        <!-- 分类选择面板 -->
        <div v-if="showCategoryPanel" class="category-panel">
          <div class="category-header">
            <span class="category-title">🎯 选择分类</span>
            <i class="el-icon-close category-close" @click="showCategoryPanel = false"></i>
          </div>
          <div class="category-list">
            <div 
              v-for="(series, index) in hotSeriesList" 
              :key="index"
              class="category-item"
              :class="{ 'category-active': selectedHotSeries === series }"
              @click="selectCategory(series)">
              <i class="el-icon-star-on"></i>
              {{ series }}
            </div>
            <div v-if="hotSeriesList.length === 0" class="category-empty">
              <i class="el-icon-box"></i>
              <p>暂无分类数据</p>
            </div>
          </div>
          <div class="category-footer">
            <el-button size="small" @click="clearCategoryFilter">
              <i class="el-icon-refresh-left"></i> 清除筛选
            </el-button>
          </div>
        </div>
        
        <div class="products-content-wrapper">
          <div class="products-grid">
            <div 
              v-for="item in itemData" 
              :key="item.id" 
              class="product-card-wrapper">
              <a :href="'/shop/detail?id='+item.id" class="product-link">
                <div class="product-card">
                  <div class="product-image-container">
                    <img 
                      :src="item.image || hamburgUrl"
                      class="product-image" 
                      alt="商品图片"
                      @error="handleImageError">
                    <div class="product-overlay">
                      <i class="el-icon-view overlay-icon"></i>
                    </div>
                    <!-- PK按钮 -->
                    <div 
                      class="pk-button" 
                      :class="{ 'pk-button-selected': isItemSelected(item) }"
                      @click="handlePkClick($event, item)">
                      <i v-if="isItemSelected(item)" class="el-icon-check"></i>
                      {{ isItemSelected(item) ? '已选' : 'PK' }}
                    </div>
                  </div>
                  
                  <div class="product-info">
                    <h3 class="product-title">{{ item.title }}</h3>
                    <p class="product-description">{{ item.sellPoint }}</p>
                    
                    <div class="product-footer">
                      <div class="price-container">
                        <span class="price-symbol">¥</span>
                        <span class="price-value">{{ item.price }}</span>
                      </div>
                      <div class="cart-icon">
                        <i class="el-icon-s-goods"></i>
                      </div>
                    </div>
                  </div>
                </div>
              </a>
            </div>
          </div>
          
          <!-- 空状态 -->
          <div v-if="itemData.length === 0" class="empty-state">
            <i class="el-icon-box empty-icon"></i>
            <p class="empty-text">暂无商品数据</p>
            <p class="empty-debug">调试信息: {{ debugInfo }}</p>
          </div>
        </div>
      </div>
    </div>

    <!-- PK选择面板 -->
    <div v-if="selectedPkItems.length > 0" class="pk-panel">
      <div class="pk-panel-content">
        <!-- 左侧：已选商品列表 -->
        <div class="pk-selected-items">
          <div 
            v-for="item in selectedPkItems" 
            :key="item.id" 
            class="pk-selected-item">
            <img 
              :src="item.image || hamburgUrl" 
              class="pk-item-image" 
              alt="商品图片">
            <div class="pk-item-info">
              <p class="pk-item-title">{{ item.title }}</p>
              <p class="pk-item-price">¥{{ item.price }}</p>
            </div>
            <i 
              class="el-icon-close pk-item-remove" 
              @click="removePkItem(item)"></i>
          </div>
        </div>

        <!-- 中间：提示信息 -->
        <div class="pk-panel-hint">
          最多还可再选择{{ 3 - selectedPkItems.length }}个商品
        </div>

        <!-- 右侧：操作按钮 -->
        <div class="pk-panel-actions">
          <el-button 
            class="pk-action-btn pk-clear-btn"
            @click="clearAllPkItems">
            清空
          </el-button>
          <el-button 
            class="pk-action-btn pk-exit-btn"
            @click="exitPkMode">
            退出
          </el-button>
          <el-button 
            type="primary"
            class="pk-action-btn pk-compare-btn"
            :disabled="selectedPkItems.length < 2"
            @click="startCompare">
            开始对比 ({{ selectedPkItems.length }})
          </el-button>
        </div>
      </div>
    </div>
    
    <!-- AI助手组件 -->
    <AiAssistant />
  </div>
</template>

<script>
import request from "@/utils/request";
import AiAssistant from "@/components/shop/AiAssistant.vue";

export default {
  name: "ShopView",
  components: {
    AiAssistant
  },
  data() {
    return {
      // 查询的关键词
      search: '',
      // 收到的商品数据
      itemData: [],
      //汉堡Url
      hamburgUrl: "https://shadow.elemecdn.com/app/element/hamburger.9cf7b091-55e9-11e9-a976-7f4d0b07eef6.png",
      // 调试信息
      debugInfo: '正在加载...',
      // PK选中的商品列表
      selectedPkItems: [],
      // 选中的筛选项
      selectedFilter: '',
      // 分类列表
      hotSeriesList: [],
      // 当前选中的分类
      selectedHotSeries: '',
      // 显示分类面板
      showCategoryPanel: false,
      // 价格排序状态: '' - 无排序, 'asc' - 升序, 'desc' - 降序
      priceSortOrder: ''
    };
  },
  created() {
    this.loadData();
    document.title = "悦购商城";
    
    // 如果3秒后还没有数据，显示模拟数据用于测试UI
    setTimeout(() => {
      if (this.itemData.length === 0) {
        this.loadMockData();
      }
    }, 3000);
  },
  methods: {
    // 选择筛选项
    selectFilter(filter) {
      this.selectedFilter = filter;
      console.log('选中的筛选项:', filter);
      
      // 处理综合排序 - 恢复默认排序
      if (filter === 'comprehensive') {
        this.showCategoryPanel = false;
        this.priceSortOrder = '';
        this.selectedHotSeries = '';
        this.loadData(); // 重新加载数据，恢复默认排序
        this.$message.success('已恢复默认排序');
      }
      // 处理分类筛选
      else if (filter === 'category') {
        this.loadHotSeriesList();
        this.showCategoryPanel = !this.showCategoryPanel;
      } 
      // 处理价格排序
      else if (filter === 'price') {
        // 处理价格排序: 无排序 -> 升序 -> 降序 -> 无排序 (循环)
        if (this.priceSortOrder === '') {
          this.priceSortOrder = 'asc';
          this.sortByPrice('asc');
          this.$message.success('价格按升序排列');
        } else if (this.priceSortOrder === 'asc') {
          this.priceSortOrder = 'desc';
          this.sortByPrice('desc');
          this.$message.success('价格按降序排列');
        } else {
          this.priceSortOrder = '';
          this.selectedFilter = '';
          this.loadData(); // 恢复原始排序
          this.$message.info('已取消价格排序');
        }
        this.showCategoryPanel = false;
      } else {
        this.showCategoryPanel = false;
      }
    },
    
    // 按价格排序
    sortByPrice(order) {
      if (order === 'asc') {
        // 升序排列
        this.itemData.sort((a, b) => {
          const priceA = parseFloat(a.price) || 0;
          const priceB = parseFloat(b.price) || 0;
          return priceA - priceB;
        });
        console.log('商品已按价格升序排列');
      } else if (order === 'desc') {
        // 降序排列
        this.itemData.sort((a, b) => {
          const priceA = parseFloat(a.price) || 0;
          const priceB = parseFloat(b.price) || 0;
          return priceB - priceA;
        });
        console.log('商品已按价格降序排列');
      }
    },
    
    // 加载所有分类
    loadHotSeriesList() {
      request.get('/itemParams/getHotSeriesList').then(res => {
        console.log('分类列表响应:', res);
        if (res.code === '0') {
          this.hotSeriesList = res.data || [];
          console.log('获取到的分类:', this.hotSeriesList);
        }
      }).catch(error => {
        console.error('加载分类失败:', error);
        this.$message.error('加载分类失败');
      });
    },
    
    // 选择分类
    selectCategory(hotSeries) {
      this.selectedHotSeries = hotSeries;
      this.showCategoryPanel = false;
      this.loadDataByHotSeries(hotSeries);
    },
    
    // 根据分类加载商品
    loadDataByHotSeries(hotSeries) {
      console.log('根据分类加载商品:', hotSeries);
      this.debugInfo = '正在按分类筛选...';
      // 重置价格排序状态
      this.priceSortOrder = '';
      request.get('/item/getByHotSeries', {
        params: {
          hotSeries: hotSeries,
          search: this.search
        }
      }).then(res => {
        console.log('分类商品响应:', res);
        if (res.code === '0') {
          this.itemData = (res.data || []).reverse();
          this.debugInfo = `找到 ${this.itemData.length} 个"${hotSeries}"分类的商品`;
          this.$message.success(`已切换到"${hotSeries}"分类`);
        }
      }).catch(error => {
        console.error('加载分类商品失败:', error);
        this.$message.error('加载分类商品失败');
      });
    },
    
    // 清除分类筛选
    clearCategoryFilter() {
      this.selectedHotSeries = '';
      this.selectedFilter = '';
      this.showCategoryPanel = false;
      this.loadData();
    },
    
    loadData() {
      console.log('开始加载商品数据...');
      this.debugInfo = '正在请求数据...';
      // 重置价格排序状态
      this.priceSortOrder = '';
      request.get('/item/getAll',{
        params: {
          search: this.search,
        }
      }).then(res => {
        console.log('商品数据响应:', res);
        // 倒序显示商品
        this.itemData = (res.data || []).reverse();
        this.debugInfo = `请求成功，获取到 ${this.itemData.length} 条数据（已倒序）`;
        console.log('商品数据已设置（倒序）:', this.itemData);
      }).catch(error => {
        console.error('加载商品数据失败:', error);
        this.debugInfo = `请求失败: ${error.message || '网络错误'}`;
        this.$message.error('加载商品数据失败，请检查网络连接');
        this.itemData = [];
      })
    },
    handleImageError(event) {
      // 图片加载失败时使用默认图片
      event.target.src = this.hamburgUrl;
    },
    // 处理PK按钮点击
    handlePkClick(event, item) {
      event.preventDefault(); // 阻止链接跳转
      event.stopPropagation(); // 阻止事件冒泡
      
      const index = this.selectedPkItems.findIndex(i => i.id === item.id);
      
      if (index > -1) {
        // 如果已选中，则取消选中
        this.selectedPkItems.splice(index, 1);
        this.$message.success('已取消选择');
      } else {
        // 如果未选中，检查是否达到上限
        if (this.selectedPkItems.length >= 3) {
          this.$message.warning('最多只能选择3个商品进行PK');
          return;
        }
        // 添加到选中列表
        this.selectedPkItems.push(item);
        this.$message.success(`已选择商品（${this.selectedPkItems.length}/3）`);
      }
    },
    // 检查商品是否被选中
    isItemSelected(item) {
      return this.selectedPkItems.some(i => i.id === item.id);
    },
    // 移除选中的商品
    removePkItem(item) {
      const index = this.selectedPkItems.findIndex(i => i.id === item.id);
      if (index > -1) {
        this.selectedPkItems.splice(index, 1);
        this.$message.success('已取消选择');
      }
    },
    // 清空所有选中的商品
    clearAllPkItems() {
      this.selectedPkItems = [];
      this.$message.success('已清空所有选择');
    },
    // 退出PK模式
    exitPkMode() {
      this.selectedPkItems = [];
      this.$message.info('已退出对比模式');
    },
    // 开始对比
    startCompare() {
      if (this.selectedPkItems.length < 2) {
        this.$message.warning('请至少选择2个商品进行对比');
        return;
      }
      
      // 跳转到对比页面，并传递选中的商品数据
      this.$router.push({
        name: 'compare',
        params: {
          items: this.selectedPkItems
        }
      });
    },
    loadMockData() {
      // 加载模拟数据用于测试UI（倒序显示）
      this.itemData = [
        {
          id: 1,
          title: '手账本',
          sellPoint: '三莹月周间手帐本日式手账本记事日记笔记本子 日程手账周计划本',
          price: 19.99,
          image: 'https://gd2.alicdn.com/imgextra/i4/132942065/O1CN015slStJ1R7oUcJMOVB_!!132942065.jpg_400x400.jpg'
        },
        {
          id: 2,
          title: '小米10Pro',
          sellPoint: '【咨询减钱+现货速发】xiaomi/小米10 5G手机全网通官方旗舰小米官网10至尊版正品K40pro新品11小米手机10s',
          price: 2999.00,
          image: 'https://gw.alicdn.com/imgextra/i2/2208143412112/O1CN01Ucp0kn1RTLCyjjKAq_!!2208143412112.jpg_Q75.jpg_.webp'
        },
        {
          id: 3,
          title: '红米K60',
          sellPoint: '【抢先加购 3日0点开抢】Redmi K60手机红米k60手机小米手机小米官方旗舰店官网新品正品redmik60',
          price: 2699.00,
          image: 'https://gd2.alicdn.com/imgextra/i3/368976905/O1CN01Bmrztb20sXdfYmxzi_!!368976905.jpg_400x400.jpg'
        },
        {
          id: 4,
          title: '外星人笔记本',
          sellPoint: 'ALIENWARE/外星人高端游戏本吃鸡电竞1517英寸独显笔记本电脑学生',
          price: 3580.00,
          image: 'https://gd1.alicdn.com/imgextra/i1/2214800833667/O1CN01TKrNN51cxXBZaNxA4_!!2214800833667.jpg'
        },
        {
          id: 5,
          title: '乐事薯片',
          sellPoint: '乐事薯片大包装休闲食品膨化平价小吃零食大礼包整箱批发官方旗舰',
          price: 21.00,
          image: 'https://gw.alicdn.com/imgextra/i4/1048187520/O1CN01DtbxdB25QDEIFViNh_!!0-item_pic.jpg_Q75.jpg_.webp'
        },
        {
          id: 6,
          title: '倩碧润肤乳液',
          sellPoint: '【38开抢】倩碧匀净卓研润肤乳液焕白肌肤提亮肤色舒缓维稳',
          price: 430.00,
          image: 'https://gw.alicdn.com/imgextra/i3/1653734047/O1CN01IhMjWr1flZh1NXBGZ_!!1653734047.jpg_Q75.jpg_.webp'
        }
      ].reverse();
      this.debugInfo = `已加载模拟数据，共 ${this.itemData.length} 条商品（已倒序）`;
      console.log('已加载模拟数据（倒序）:', this.itemData);
    }
  }
}
</script>

<style scoped>
/* 全局容器 */
.shop-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #e0e5ec 0%, #c7d0d9 50%, #aeb9c4 100%);
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  position: relative;
}

/* 添加微妙的纹理背景 */
.shop-container::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-image: 
    radial-gradient(circle at 20% 80%, rgba(120, 119, 198, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 80% 20%, rgba(255, 119, 198, 0.15) 0%, transparent 50%),
    radial-gradient(circle at 40% 40%, rgba(120, 219, 255, 0.15) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

/* 搜索区域 */
.search-section {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
  border-bottom: 1px solid rgba(255, 255, 255, 0.2);
}

.search-container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 30px 40px;
  display: flex;
  align-items: center;
  gap: 50px;
}

.logo-section {
  flex-shrink: 0;
}

.logo-link {
  display: block;
  transition: transform 0.3s ease;
}

.logo-link:hover {
  transform: scale(1.05);
}

/* 纯CSS文字Logo */
.logo-text {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 50%, #ff6b35 100%);
  background-size: 200% 200%;
  border-radius: 16px;
  box-shadow: 0 4px 20px rgba(255, 107, 53, 0.4);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  animation: gradientShift 3s ease infinite;
}

.logo-text:hover {
  transform: translateY(-3px) scale(1.05);
  box-shadow: 0 8px 30px rgba(255, 107, 53, 0.6);
}

@keyframes gradientShift {
  0%, 100% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
}

.logo-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 50px;
  height: 50px;
  background: rgba(255, 255, 255, 0.2);
  backdrop-filter: blur(10px);
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  transition: all 0.3s ease;
}

.logo-text:hover .logo-icon {
  background: rgba(255, 255, 255, 0.3);
  transform: rotate(10deg) scale(1.1);
}

.logo-icon i {
  font-size: 28px;
  color: white;
  font-weight: bold;
}

.logo-content {
  display: flex;
  flex-direction: column;
  gap: 2px;
  line-height: 1;
}

.logo-main {
  font-size: 32px;
  font-weight: 800;
  color: white;
  letter-spacing: 2px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.2);
  font-family: 'Microsoft YaHei', 'PingFang SC', -apple-system, BlinkMacSystemFont, sans-serif;
}

.logo-sub {
  font-size: 14px;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.9);
  letter-spacing: 3px;
  text-transform: uppercase;
  font-family: 'Arial', 'Helvetica', sans-serif;
}

.search-box {
  flex: 1;
  max-width: 600px;
}

.search-input-wrapper {
  display: flex;
  gap: 12px;
  align-items: center;
}

.search-input {
  flex: 1;
  position: relative;
}

.search-input >>> .el-input__inner {
  height: 50px;
  border-radius: 25px;
  border: 2px solid rgba(200, 210, 220, 0.8);
  font-size: 16px;
  padding: 0 20px 0 50px;
  transition: all 0.3s ease;
  background: rgba(240, 245, 250, 0.9);
  backdrop-filter: blur(10px);
  text-align: left;
}

.search-input >>> .el-input__inner:focus {
  border-color: #ff6b35;
  background: white;
  box-shadow: 0 0 0 3px rgba(255, 107, 53, 0.1);
}

.search-icon {
  color: #6c757d;
  font-size: 18px;
  position: absolute;
  left: 18px;
  top: 50%;
  transform: translateY(-50%);
  z-index: 10;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
}

.search-btn {
  height: 50px;
  padding: 0 30px;
  border-radius: 25px;
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  border: none;
  font-size: 16px;
  font-weight: 600;
  transition: all 0.3s ease;
  box-shadow: 0 4px 15px rgba(255, 107, 53, 0.3);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.search-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 25px rgba(255, 107, 53, 0.4);
}

/* 商品展示区域 */
.products-section {
  padding: 50px 0 60px;
  position: relative;
  z-index: 1;
}

.products-container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 0 40px;
  display: flex;
  gap: 40px;
  align-items: flex-start;
}

/* 左侧筛选栏 */
.filter-sidebar {
  flex: 0 0 110px;
  display: flex;
  flex-direction: column;
  gap: 25px;
  background: rgba(255, 255, 255, 0.95);
  padding: 30px 15px;
  border-radius: 16px;
  box-shadow: 0 6px 30px rgba(0, 0, 0, 0.12);
  position: sticky;
  top: 140px;
  align-self: flex-start;
  backdrop-filter: blur(10px);
  border: 2px solid rgba(220, 225, 230, 0.8);
  position: relative;
}

.filter-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 22px 12px;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  background: rgba(248, 249, 250, 0.8);
  border: 2px solid transparent;
  position: relative;
  overflow: hidden;
}

.filter-item::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.1), rgba(247, 147, 30, 0.1));
  opacity: 0;
  transition: opacity 0.3s ease;
}

.filter-item:hover {
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.05), rgba(247, 147, 30, 0.05));
  border-color: #ff6b35;
  transform: translateX(5px);
  box-shadow: 0 4px 15px rgba(255, 107, 53, 0.2);
}

.filter-item:hover::before {
  opacity: 1;
}

.filter-item.active {
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  border-color: #ff6b35;
  box-shadow: 0 4px 20px rgba(255, 107, 53, 0.4);
  transform: translateX(5px);
}

.filter-item.active i {
  color: white;
  animation: filterBounce 0.6s ease;
}

.filter-item.active .filter-text {
  color: white;
  font-weight: 700;
}

.filter-item i {
  font-size: 28px;
  color: #666;
  margin-bottom: 8px;
  transition: all 0.3s ease;
  position: relative;
  z-index: 1;
}

.filter-item:hover i {
  color: #ff6b35;
  transform: scale(1.2);
}

.filter-text {
  font-size: 14px;
  color: #333;
  font-weight: 600;
  transition: all 0.3s ease;
  position: relative;
  z-index: 1;
  text-align: center;
}

.sort-arrow {
  font-size: 16px;
  margin-top: 2px;
  animation: arrowBounce 0.6s ease;
}

@keyframes arrowBounce {
  0%, 100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-3px);
  }
}

@keyframes filterBounce {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
}

/* 分类选择遮罩层 */
.category-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  animation: fadeIn 0.3s ease-out;
  backdrop-filter: blur(5px);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* 分类选择面板 */
.category-panel {
  position: fixed;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 500px;
  max-width: 90vw;
  max-height: 80vh;
  background: white;
  border-radius: 20px;
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
  z-index: 1000;
  animation: slideDown 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
}

@keyframes slideDown {
  from {
    opacity: 0;
    transform: translate(-50%, -60%);
  }
  to {
    opacity: 1;
    transform: translate(-50%, -50%);
  }
}

.category-header {
  padding: 25px 30px;
  border-bottom: 2px solid #f0f0f0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  border-radius: 20px 20px 0 0;
  box-shadow: 0 2px 10px rgba(255, 107, 53, 0.2);
}

.category-title {
  font-size: 20px;
  font-weight: 700;
  color: white;
  letter-spacing: 1px;
}

.category-close {
  font-size: 20px;
  color: white;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.category-close:hover {
  transform: rotate(90deg);
}

.category-list {
  max-height: 50vh;
  overflow-y: auto;
  padding: 20px 25px;
  flex: 1;
}

.category-list::-webkit-scrollbar {
  width: 6px;
}

.category-list::-webkit-scrollbar-track {
  background: #f0f0f0;
  border-radius: 3px;
}

.category-list::-webkit-scrollbar-thumb {
  background: #ff6b35;
  border-radius: 3px;
}

.category-item {
  padding: 18px 24px;
  margin-bottom: 12px;
  background: #f8f9fa;
  border-radius: 12px;
  cursor: pointer;
  transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border: 2px solid transparent;
  font-size: 16px;
  font-weight: 500;
  color: #333;
  display: flex;
  align-items: center;
  gap: 12px;
}

.category-item i {
  font-size: 18px;
  color: #ff6b35;
  transition: all 0.3s ease;
}

.category-item:hover {
  background: linear-gradient(135deg, rgba(255, 107, 53, 0.15), rgba(247, 147, 30, 0.15));
  border-color: #ff6b35;
  transform: translateX(8px) scale(1.02);
  box-shadow: 0 6px 20px rgba(255, 107, 53, 0.3);
}

.category-item:hover i {
  transform: scale(1.3) rotate(15deg);
}

.category-item.category-active {
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  color: white;
  border-color: #ff6b35;
  box-shadow: 0 6px 25px rgba(255, 107, 53, 0.5);
  font-weight: 700;
  transform: scale(1.05);
}

.category-item.category-active i {
  color: white;
  animation: starPulse 1s ease-in-out infinite;
}

@keyframes starPulse {
  0%, 100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.3);
  }
}

.category-empty {
  padding: 60px 20px;
  text-align: center;
  color: #999;
  font-size: 15px;
}

.category-empty i {
  font-size: 48px;
  color: #ddd;
  margin-bottom: 15px;
  display: block;
}

.category-empty p {
  margin: 0;
}

.category-footer {
  padding: 20px 25px;
  border-top: 2px solid #f0f0f0;
  text-align: center;
  background: #fafafa;
  border-radius: 0 0 20px 20px;
}

.category-footer .el-button {
  width: 100%;
  height: 45px;
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  border: none;
  color: white;
  font-weight: 600;
  font-size: 15px;
  transition: all 0.3s ease;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.category-footer .el-button:hover {
  transform: translateY(-3px);
  box-shadow: 0 6px 20px rgba(255, 107, 53, 0.5);
}

.category-footer .el-button i {
  font-size: 18px;
}

.products-content-wrapper {
  flex: 1;
  min-width: 0;
}

.products-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 35px;
  margin-bottom: 50px;
  grid-auto-rows: 1fr;
}

.product-card-wrapper {
  transition: transform 0.3s ease;
  display: flex;
  min-height: 500px;
}

.product-card-wrapper:hover {
  transform: translateY(-10px);
}

.product-link {
  text-decoration: none;
  color: inherit;
  display: flex;
  width: 100%;
}

.product-card {
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(10px);
  border-radius: 20px;
  overflow: hidden;
  box-shadow: 0 6px 25px rgba(0, 0, 0, 0.1);
  border: 2px solid rgba(220, 225, 230, 0.8);
  transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
  width: 100%;
  display: flex;
  flex-direction: column;
}

.product-card:hover {
  background: rgba(255, 255, 255, 1);
  box-shadow: 0 15px 50px rgba(0, 0, 0, 0.18);
  transform: translateY(-3px);
  border: 2px solid rgba(255, 107, 53, 0.6);
}

.product-image-container {
  position: relative;
  overflow: hidden;
  height: 260px;
  background: linear-gradient(135deg, #e8edf2 0%, #d1d9e0 100%);
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-image {
  width: 100%;
  height: 100%;
  object-fit: contain;
  transition: transform 0.3s ease;
}

.product-card:hover .product-image {
  transform: scale(1.05);
}

.product-overlay {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.product-card:hover .product-overlay {
  opacity: 1;
}

.overlay-icon {
  color: white;
  font-size: 32px;
}

/* PK按钮样式 */
.pk-button {
  position: absolute;
  top: 15px;
  right: 15px;
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  color: white;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 18px;
  border-radius: 22px;
  cursor: pointer;
  opacity: 0;
  transform: translateY(-10px);
  transition: all 0.3s ease;
  box-shadow: 0 5px 18px rgba(255, 107, 53, 0.4);
  z-index: 10;
  user-select: none;
  display: flex;
  align-items: center;
  gap: 5px;
}

.product-card:hover .pk-button {
  opacity: 1;
  transform: translateY(0);
}

.pk-button:hover {
  transform: scale(1.12) translateY(0);
  box-shadow: 0 7px 25px rgba(255, 107, 53, 0.6);
}

/* PK按钮选中状态 */
.pk-button-selected {
  opacity: 1 !important;
  background: linear-gradient(135deg, #28a745 0%, #20c997 100%);
  box-shadow: 0 4px 15px rgba(40, 167, 69, 0.4);
  transform: translateY(0) !important;
}

.pk-button-selected:hover {
  transform: scale(1.1) translateY(0) !important;
  box-shadow: 0 6px 20px rgba(40, 167, 69, 0.6);
}

.product-info {
  padding: 25px;
  flex: 1;
  display: flex;
  flex-direction: column;
}

.product-title {
  font-size: 17px;
  font-weight: 600;
  color: #2c3e50;
  margin: 0 0 12px 0;
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  transition: color 0.3s ease;
}

.product-card:hover .product-title {
  color: #ff6b35;
}

.product-description {
  font-size: 14px;
  color: #6c757d;
  line-height: 1.6;
  margin: 0 0 20px 0;
  flex: 1;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.product-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: auto;
  padding-top: 5px;
}

.price-container {
  display: flex;
  align-items: baseline;
  gap: 3px;
}

.price-symbol {
  font-size: 16px;
  color: #ff6b35;
  font-weight: 600;
}

.price-value {
  font-size: 24px;
  color: #ff6b35;
  font-weight: 700;
}

.cart-icon {
  width: 42px;
  height: 42px;
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 18px;
  transition: all 0.3s ease;
  cursor: pointer;
}

.cart-icon:hover {
  transform: scale(1.15);
  box-shadow: 0 6px 20px rgba(255, 107, 53, 0.5);
}

/* 空状态 */
.empty-state {
  text-align: center;
  padding: 100px 40px;
  color: #6c757d;
  background: rgba(255, 255, 255, 0.6);
  backdrop-filter: blur(10px);
  border-radius: 24px;
  border: 1px solid rgba(255, 255, 255, 0.3);
  margin: 30px;
}

.empty-icon {
  font-size: 72px;
  color: #dee2e6;
  margin-bottom: 20px;
}

.empty-text {
  font-size: 20px;
  margin: 0 0 12px 0;
}

.empty-debug {
  font-size: 15px;
  color: #999;
  margin: 0;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .search-container {
    flex-direction: column;
    gap: 20px;
    padding: 20px;
  }
  
  .logo {
    width: 150px;
    height: 60px;
  }
  
  .search-input-wrapper {
    width: 100%;
  }
  
  .products-container {
    padding: 0 15px;
    flex-direction: column;
  }
  
  /* 移动端筛选栏改为横向 */
  .filter-sidebar {
    flex: none;
    flex-direction: row;
    width: 100%;
    padding: 15px 10px;
    position: relative;
    top: auto;
    overflow-x: auto;
  }
  
  .filter-item {
    padding: 15px 10px;
    min-width: 70px;
    flex-shrink: 0;
  }
  
  .filter-item i {
    font-size: 22px;
    margin-bottom: 5px;
  }
  
  .filter-text {
    font-size: 12px;
  }
  
  .filter-item:hover {
    transform: translateY(-3px);
  }
  
  .filter-item.active {
    transform: translateY(-3px);
  }
  
  .products-grid {
    grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
    gap: 20px;
  }

  .pk-panel-content {
    flex-direction: column;
    gap: 15px;
    padding: 15px 20px;
  }

  .pk-selected-items {
    max-width: 100%;
    width: 100%;
    justify-content: flex-start;
  }

  .pk-panel-hint {
    text-align: left;
  }

  .pk-panel-actions {
    width: 100%;
    justify-content: flex-end;
  }
}

@media (max-width: 480px) {
  .products-grid {
    grid-template-columns: 1fr;
    gap: 15px;
  }
  
  .product-image-container {
    height: 200px;
  }
  
  .product-info {
    padding: 15px;
  }
}

/* PK选择面板 */
.pk-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(255, 255, 255, 0.98);
  backdrop-filter: blur(20px);
  box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
  border-top: 2px solid rgba(220, 225, 230, 0.8);
  z-index: 1000;
  animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
  from {
    transform: translateY(100%);
  }
  to {
    transform: translateY(0);
  }
}

.pk-panel-content {
  max-width: 1400px;
  margin: 0 auto;
  padding: 20px 30px;
  display: flex;
  align-items: center;
  gap: 30px;
  justify-content: space-between;
}

.pk-selected-items {
  display: flex;
  gap: 15px;
  flex: 0 0 auto;
  max-width: 600px;
  overflow-x: auto;
}

.pk-selected-item {
  display: flex;
  align-items: center;
  gap: 10px;
  background: white;
  border: 1px solid #e0e0e0;
  border-radius: 8px;
  padding: 10px 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  transition: all 0.3s ease;
  position: relative;
  min-width: 180px;
  max-width: 180px;
}

.pk-selected-item:hover {
  border-color: #ff6b35;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.12);
}

.pk-item-image {
  width: 50px;
  height: 50px;
  object-fit: contain;
  border-radius: 6px;
  background: #f8f9fa;
  padding: 4px;
  flex-shrink: 0;
}

.pk-item-info {
  flex: 1;
  min-width: 0;
}

.pk-item-title {
  margin: 0 0 4px 0;
  font-size: 13px;
  font-weight: 500;
  color: #333;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pk-item-price {
  margin: 0;
  font-size: 14px;
  font-weight: 700;
  color: #ff6b35;
}

.pk-item-remove {
  font-size: 16px;
  color: #999;
  cursor: pointer;
  transition: all 0.3s ease;
  padding: 2px;
  flex-shrink: 0;
}

.pk-item-remove:hover {
  color: #ff4444;
  transform: scale(1.2);
}

.pk-panel-hint {
  flex: 1;
  text-align: center;
  font-size: 14px;
  color: #999;
  white-space: nowrap;
  min-width: 150px;
}

.pk-panel-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-shrink: 0;
}

.pk-action-btn {
  height: 40px;
  padding: 0 24px;
  font-size: 14px;
  border-radius: 4px;
  transition: all 0.3s ease;
}

.pk-clear-btn {
  background: white;
  border: 1px solid #dcdfe6;
  color: #606266;
}

.pk-clear-btn:hover {
  background: #f5f7fa;
  border-color: #c0c4cc;
}

.pk-exit-btn {
  background: white;
  border: 1px solid #dcdfe6;
  color: #606266;
}

.pk-exit-btn:hover {
  background: #f5f7fa;
  border-color: #c0c4cc;
}

.pk-compare-btn {
  background: linear-gradient(135deg, #ff6b35 0%, #f7931e 100%);
  border: none;
  color: white;
  font-weight: 600;
  box-shadow: 0 2px 12px rgba(255, 107, 53, 0.3);
}

.pk-compare-btn:hover:not(:disabled) {
  box-shadow: 0 4px 16px rgba(255, 107, 53, 0.4);
  transform: translateY(-1px);
}

.pk-compare-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* 动画效果 */
.product-card-wrapper {
  animation: fadeInUp 0.6s ease-out;
  animation-fill-mode: both;
}

.product-card-wrapper:nth-child(1) { animation-delay: 0.1s; }
.product-card-wrapper:nth-child(2) { animation-delay: 0.2s; }
.product-card-wrapper:nth-child(3) { animation-delay: 0.3s; }
.product-card-wrapper:nth-child(4) { animation-delay: 0.4s; }
.product-card-wrapper:nth-child(5) { animation-delay: 0.5s; }
.product-card-wrapper:nth-child(6) { animation-delay: 0.6s; }

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(30px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}
</style>
